module.exports = (option,app)=>{
    return async function auth(ctx,next){
        /* 实现中间件 */
        const url = ctx.url;
        if(url == '/getToken'){
            await next()
        }else{
            var apikey = ctx.query.apikey
            try {
                await app.jwt.verify(apikey, app.config.jwt.secret);
                await next();
            } catch (err) {
                ctx.body = {
                    code: 400,
                    message: 'token失效或解析错误'
                }
            }
        }
        
    }
}